<template>
  <div class="app-container">

    <el-col :span="24"
            class="card-box">
      <el-card>
        <div slot="header">
          <span>转接详情信息</span>
        </div>
        <div class="el-table el-table--enable-row-hover el-table--medium">
          <table cellspacing="0"
                 style="width: 100%;">

            <el-row :gutter="20">
              <!--部门数据-->
              <el-col :span="12"
                      :xs="24">
                <el-form v-loading="loading"
                         :data="myOrderList">
                  <el-form-item label="工单编号:"
                                prop="orderNo">
                    <p>{{myOrderList.orderNo}}</p>
                  </el-form-item>
                  <el-form-item label="工单类别:"
                                prop="roType">
                    <p>{{myOrderList.roType}}</p>
                  </el-form-item>
                  <el-form-item label="问题描述:"
                                prop="roDescription">
                    <p>{{myOrderList.roDescription}}</p>
                  </el-form-item>
                  <el-form-item label="提交时间:"
                                prop="createTime">
                    <p>{{myOrderList.createTime}}</p>
                  </el-form-item>
                  <el-form-item label="工作状态:"
                                prop="roStatus">
                    <p>{{myOrderList.roStatus}}</p>
                  </el-form-item>

                  <el-form-item label="申请转接人:"
                                prop="deptSumbitP">
                    <p>{{myOrderList.deptSumbitP}}</p>
                  </el-form-item>
                  <el-form-item label="申请转接理由:"
                                prop="describe">
                    <p>{{myOrderList.describe}}</p>
                  </el-form-item>
                  <el-form-item label="申请时间:"
                                prop="transferTime">
                    <p>{{myOrderList.transferTime}}</p>
                  </el-form-item>
                </el-form>
              </el-col>
              <el-col :span="12"
                      :xs="24">
                <div>
                  <el-image src="https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg"></el-image>
                </div>
               
                <div>
                  <el-image src="https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg"></el-image>
                </div>
              </el-col>
            </el-row>
          </table>
        </div>
      </el-card>
    </el-col>

    <el-col :span="24"
            class="card-box">
      <el-card>
        <div slot="header">
          <span>转接方式</span>
        </div>
        <div class="el-table el-table--enable-row-hover el-table--medium">
          <table cellspacing="0"
                 style="width: 100%;">
            <el-row :gutter="20">
              <!--部门数据-->
              <el-col :span="4"
                      :xs="24">
                <!-- <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入部门名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div> -->
                <div class="head-container">
                  <el-tree :data="deptOptions"
                           :props="defaultProps"
                           :expand-on-click-node="false"
                           :filter-node-method="filterNode"
                           ref="tree"
                           default-expand-all
                           @node-click="handleNodeClick" />
                </div>
              </el-col>
              <el-col :span="20"
                      :xs="24">
                <el-table v-loading="loading"
                          :data="userList">
                  <el-table-column label="用户昵称"
                                   align="center"
                                   key="nickName"
                                   prop="nickName"
                                   v-if="columns[0].visible"
                                   :show-overflow-tooltip="true" />
                  <el-table-column label="部门"
                                   align="center"
                                   key="deptName"
                                   prop="dept.deptName"
                                   v-if="columns[1].visible"
                                   :show-overflow-tooltip="true" />
                  <el-table-column label="手机号码"
                                   align="center"
                                   key="phonenumber"
                                   prop="phonenumber"
                                   v-if="columns[2].visible"
                                   width="120" />

                  <el-table-column label="是否转接"
                                   align="center"
                                   width="160"
                                   class-name="small-padding fixed-width">
                    <template slot-scope="scope"
                              v-if="scope.row.userId !== 1">
                      <el-button type="danger"
                                 icon="el-icon-search"
                                 size="mini"
                                 @click="handelRefuse(scope.row)">拒绝</el-button>
                      <el-button type="primary"
                                 icon="el-icon-refresh"
                                 size="mini"
                                 @click="handelTransfer(scope.row)">转接</el-button>

                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
          </table>
        </div>
      </el-card>
    </el-col>

  </div>
</template>

<script>
import {
  selectTransByNo,
  listUser,
  delRefuse,
  delTransfer,
} from '@/api/repair/transferdatails'
import { treeselect } from '@/api/system/dept'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
  components: { Treeselect },
  name: 'Transferdatails',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定时任务表格数据
      myOrderList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 是否显示详细弹出层
      openView: false,
      // 用户表格数据
      userList: null,
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: 'children',
        label: 'label',
      },
      // orderNo2:"",

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined,
      },
      queryP: {
        orderNo: '',
        nickName: '',
        deptName: '',
      },
      // 列信息
      columns: [
        { key: 0, label: `用户昵称`, visible: true },
        { key: 1, label: `部门名称`, visible: true },
        { key: 2, label: `部门名称`, visible: true },
      ],
    }
  },

  methods: {
    /** 查询我的工单列表 */
    getList() {
      this.loading = true
      selectTransByNo(this.$route.params.orderNo).then((res) => {
        this.$modal.msgSuccess('查询成功')
        this.myOrderList = res.data
        console.log(this.myOrderList)
        this.queryP.orderNo = this.$route.params.orderNo
        console.log(this.queryP.orderNo)

        // console.log(res.data);
        this.total = res.total
        this.loading = false
      })
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.userList = response.rows

          this.total = response.total
          this.loading = false
        }
      )
    },
    /** 拒绝按钮操作 */
    handelRefuse(row) {
      this.queryP.deptName = row.dept.deptName
      this.queryP.nickName = row.nickName

      // const nickNames = row.nickName || this.ids;
      delRefuse(this.queryP)
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('拒绝成功')
        })
        .catch(() => {})
    },
    /** 转接按钮操作 */
    handelTransfer(row) {
      this.queryP.deptName = row.dept.deptName
      this.queryP.nickName = row.nickName

      // const nickNames = row.nickName || this.ids;
      delTransfer(this.queryP)
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('转接成功')
        })
        .catch(() => {})
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then((response) => {
        this.deptOptions = response.data
      })
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id
      this.getList()
    },
  },
  created() {
    this.getList()
    this.getTreeselect()
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val)
    },
  },
}
</script>

<style>
</style>